﻿using System.Windows.Controls;
using System.Windows.Input;
using SomethingSpacial.CustomControls;
using SomethingSpacial.ViewModel;

namespace SomethingSpacial.Views.Default
{
    public partial class NextEvent : UserControl
    {
        public NextEvent()
        {
            InitializeComponent();
//            buttonShowMap.Click += new System.Windows.RoutedEventHandler(buttonShowMap_Click);
            this.Loaded += new System.Windows.RoutedEventHandler(NextEvent_Loaded);
        }

        void NextEvent_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            ((NextEventViewModel)this.DataContext).loadEvents();
            //((EventsViewModel)LayoutRoot2.DataContext ).loadEvents();
        }

        void buttonShowMap_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ShowDirections pageDirections = new ShowDirections();
            pageDirections.Show();
        } 

        private void TwitIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Tools.OpenWindow(NextEventViewModel.TwitterUrl);
        }

        private void RssIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Tools.OpenWindow(NextEventViewModel.RssUrl);
        }

        private void FcbkIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Tools.OpenWindow(NextEventViewModel.FcbkUrl);
        }

        private void MeetingIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            string MeetingInvitePath = NextEventViewModel.MeetingInvite;

            if( MeetingInvitePath.IndexOf("http") == -1 )
            {
                string URL = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri;
                MeetingInvitePath = URL.Substring(0, URL.LastIndexOf('/')) + "/" + MeetingInvitePath; 
            }

            Tools.OpenWindow(MeetingInvitePath);
        }
    }
}
